//
//  CustomMineTableViewCellThree.m
//  ChunLaiZhuangClient
//
//  Created by zouzhisheng on 16/2/23.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "CustomMineTableViewCellThree.h"
#import "CustomButtonItem.h"
#import "MyOrderFormViewController.h"
#import "AppContext.h"
#import "AccountModel.h"
#import "LoginViewController.h"
@implementation CustomMineTableViewCellThree

- (void)awakeFromNib {
    // Initialization cod
    NSArray *imageArray=[NSArray arrayWithObjects:@"icon_daifukuan",@"icon_daifahuo",@"icon_daishouhuo",@"icon_daipingjia", nil];
    NSArray *titleArray=[NSArray arrayWithObjects:@"待付款",@"待发货",@"待收货",@"待评价", nil];
    if (!_imageArray) {
        _imageArray=[[NSMutableArray alloc] init];
    }
    for (int i=0; i<4; i++) {
        CustomButtonItem *item=[[CustomButtonItem alloc] initWithFrame:CGRectMake(i*SCREEN_WIDTH/4, 0,SCREEN_WIDTH/4, 132/2) norImage:imageArray[i] selectedImage:@"" titile:titleArray[i]];
        item.backgroundColor=[UIColor whiteColor];
        item.tag=i;
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/4-26, 5, 10, 10)];
        imageView.image=[UIImage imageNamed:@"icon_tixing"];
        imageView.hidden=YES;
        [item addSubview:imageView];
        [item addTarget:self action:@selector(toOrderView:) forControlEvents:UIControlEventTouchUpInside];
        item.titleLabel.font=[UIFont systemFontOfSize:14];
        [self addSubview:item];
        [_imageArray addObject:imageView];
    }
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 65.5, SCREEN_WIDTH, 0.5)];
    lineView.backgroundColor=[UIColor colorWithHexString:@"e1e1e1"];
    [self addSubview:lineView];

}
-(void)toOrderView:(UIButton*)bt{
     UIViewController *currentVC=[CustomMineTableViewCellThree viewController:self];
    if(!APP_CONTEXT.account) {
        [LoginViewController presentLoginViewController:currentVC withCompleteBlock:nil];
        return;
    }
    MyOrderFormViewController *orderVC=[[MyOrderFormViewController alloc] init];
    [orderVC setSelectIndex:bt.tag+1];
   
    [currentVC.navigationController pushViewController:orderVC animated:YES];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)loadData{
   
    if (APP_CONTEXT.account){
         NSArray *stateArray=[NSArray arrayWithObjects:[NSNumber numberWithInteger:APP_CONTEXT.account.data.unpaid_total],[NSNumber numberWithInteger:APP_CONTEXT.account.data.unshipped_total],[NSNumber numberWithInteger:APP_CONTEXT.account.data.shipped_total],[NSNumber numberWithInteger:APP_CONTEXT.account.data.unreviewed_total], nil];
        for (int i=0; i<4; i++) {
            UIImageView *imageView=_imageArray[i];
            if ([stateArray[i] integerValue]==0) {
                imageView.hidden=YES;
            }else{
               imageView.hidden=NO;
            }
        }
        
        
           }
}
@end
